using System;


using Impact.Web.Foundation;
using Impact.Model.Objects;
using Impact.Views;
using System.Web.UI.HtmlControls;
using System.Web.UI;
using Impact.Infrastructure.Exceptions;

namespace Impact.Web.Controls
{
    public partial class DisplayPage : Impact.Web.Foundation.DynamicPageControlBase, Impact.Views.IContentControl
    {

        /// <summary>
        /// loads the page to be displayed into the controls
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            Check.Require(page, "Page must be set before OnLoad");

            //headline.Text = page.Title;
            body.Text = page.Body;

            DateTime modified = page.ModifiedOn.HasValue ? page.ModifiedOn.Value : page.CreatedOn;

            //footer.Text = string.Format("Page last modified: {0}", modified);

            plugins3.PageData = page;
            plugins4.PageData = page;
            plugins5.PageData = page;

            base.OnLoad(e);
        }

        /// <summary>
        /// Retrieves the title for the page this control is building
        /// </summary>
        protected override string PageTitle
        {
            get { return PageData.Title; }
        }

        /// <summary>
        /// Gets or Sets the page that will be displayed on this control
        /// </summary>
        public ImpactPage PageData
        {
            get { return page; }
            set { page = value; }
        }
        private ImpactPage page;


        #region IContentControl Members

        /// <summary>
        /// sets the page that will be used as the datasource for this control
        /// </summary>
        public object DataSource
        {
            set { page = (ImpactPage)value; }
        }

        /// <summary>
        /// called to perform initialization before the control loads
        /// </summary>
        public void PreInit()
        {
            Check.Require(page, "Page must be set before PreInit() is called");
            if (page.Template != null && !string.IsNullOrEmpty(page.Template.Path))
            {
                this.Page.MasterPageFile = page.Template.Path;
            }
        }

        #endregion
    }
}